package com.fr.dialog.core;

import com.fr.base.Inter;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class ColorSelectPane extends JPanel
{
  private Color color;
  private boolean isSupportTransparent;
  private Dimension colorCellDimension;
  private Color colorCellBorderColor;
  private List colorChangeListenerList;
  private final Color[] MenuColors;
  private final Color[] MenuColors2;

  public ColorSelectPane()
  {
    this(null);
  }

  public ColorSelectPane(Color paramColor)
  {
    this.color = null;
    this.isSupportTransparent = false;
    this.colorCellDimension = new Dimension(15, 15);
    this.colorCellBorderColor = Color.gray;
    this.colorChangeListenerList = new ArrayList();
    this.MenuColors = new Color[] { Color.black, new Color(153, 51, 0), new Color(51, 51, 0), new Color(0, 51, 0), new Color(0, 51, 102), new Color(0, 0, 128), new Color(51, 51, 153), new Color(51, 51, 51), new Color(128, 0, 0), new Color(252, 102, 0), new Color(128, 128, 0), new Color(0, 128, 0), new Color(0, 128, 128), new Color(0, 0, 255), new Color(102, 102, 153), new Color(128, 128, 128), new Color(255, 0, 0), new Color(255, 153, 0), new Color(153, 204, 0), new Color(51, 153, 102), new Color(51, 204, 204), new Color(51, 102, 255), new Color(128, 0, 128), new Color(150, 150, 150), new Color(255, 0, 255), new Color(255, 204, 0), new Color(255, 255, 0), new Color(0, 255, 0), new Color(0, 255, 255), new Color(0, 204, 255), new Color(153, 51, 102), new Color(192, 192, 192), new Color(255, 153, 204), new Color(255, 204, 153), new Color(255, 255, 153), new Color(204, 255, 204), new Color(204, 255, 255), new Color(153, 204, 255), new Color(204, 153, 255), new Color(255, 255, 255) };
    this.MenuColors2 = new Color[] { new Color(153, 153, 255), new Color(153, 51, 102), new Color(255, 255, 204), new Color(204, 255, 255), new Color(102, 0, 102), new Color(255, 128, 128), new Color(0, 102, 204), new Color(204, 204, 255), new Color(0, 0, 128), new Color(255, 0, 255), new Color(255, 255, 0), new Color(0, 255, 255), new Color(128, 0, 128), new Color(128, 0, 0), new Color(0, 128, 128), new Color(0, 0, 255) };
    setColor(paramColor);
    initComponents();
  }

  private void initComponents()
  {
    removeAll();
    setLayout(new BorderLayout(0, 4));
    if (this.isSupportTransparent)
    {
      localObject = new JButton("Transparent");
      ((JButton)localObject).setCursor(new Cursor(12));
      ((JButton)localObject).addActionListener(new TransparentActionListener(this));
      add((Component)localObject, "North");
    }
    Object localObject = new JPanel();
    add((Component)localObject, "Center");
    ((JPanel)localObject).setLayout(new BoxLayout((Container)localObject, 1));
    JPanel localJPanel1 = new JPanel();
    ((JPanel)localObject).add(localJPanel1);
    localJPanel1.setLayout(new GridLayout(5, 8, 5, 5));
    for (int i = 0; i < this.MenuColors.length; ++i)
      localJPanel1.add(new ColorCell(this, this.MenuColors[i]));
    ((JPanel)localObject).add(Box.createVerticalStrut(5));
    ((JPanel)localObject).add(new JSeparator());
    ((JPanel)localObject).add(Box.createVerticalStrut(5));
    JPanel localJPanel2 = new JPanel();
    ((JPanel)localObject).add(localJPanel2);
    localJPanel2.setLayout(new GridLayout(2, 8, 5, 5));
    for (int j = 0; j < this.MenuColors2.length; ++j)
      localJPanel2.add(new ColorCell(this, this.MenuColors2[j]));
    JButton localJButton = new JButton();
    localJButton.setText(Inter.getLocText("Custom") + "...");
    localJButton.setCursor(new Cursor(12));
    localJButton.addActionListener(new CustomActionListener(this));
    add(localJButton, "South");
    revalidate();
  }

  public void addChangeListener(ChangeListener paramChangeListener)
  {
    this.colorChangeListenerList.add(paramChangeListener);
  }

  public Color getColor()
  {
    return this.color;
  }

  public void setColor(Color paramColor)
  {
    ChangeEvent localChangeEvent;
    int i;
    this.color = paramColor;
    if (this.colorChangeListenerList.size() > 0)
    {
      localChangeEvent = new ChangeEvent(this);
      for (i = 0; i < this.colorChangeListenerList.size(); ++i)
        ((ChangeListener)this.colorChangeListenerList.get(i)).stateChanged(localChangeEvent);
    }
    repaint();
  }

  public boolean isSupportTransparent()
  {
    return this.isSupportTransparent;
  }

  public void setSupportTransparent(boolean paramBoolean)
  {
    boolean bool = this.isSupportTransparent;
    this.isSupportTransparent = paramBoolean;
    if (bool != paramBoolean)
      initComponents();
  }

  public Dimension getColorCellDimension()
  {
    return this.colorCellDimension;
  }

  public void setColorCellDimension(Dimension paramDimension)
  {
    Dimension localDimension = this.colorCellDimension;
    this.colorCellDimension = paramDimension;
    if (!(localDimension.equals(this.colorCellDimension)))
      initComponents();
  }

  public Color getColorCellBorderLineColor()
  {
    return this.colorCellBorderColor;
  }

  public void setColorCellBorderLineColor(Color paramColor)
  {
    Color localColor = this.colorCellBorderColor;
    this.colorCellBorderColor = paramColor;
    if (!(localColor.equals(this.colorCellBorderColor)))
      initComponents();
  }

  class CustomActionListener
    implements ActionListener
  {
    private final ColorSelectPane this$0;

    CustomActionListener()
    {
      this.this$0 = paramColorSelectPane;
    }

    public void actionPerformed()
    {
      Color localColor = JColorChooser.showDialog(this.this$0, "Select Color.", this.this$0.getColor());
      if (localColor != null)
        this.this$0.setColor(localColor);
    }
  }

  class TransparentActionListener
    implements ActionListener
  {
    private final ColorSelectPane this$0;

    TransparentActionListener()
    {
      this.this$0 = paramColorSelectPane;
    }

    public void actionPerformed()
    {
      this.this$0.setColor(null);
    }
  }

  class ColorCell extends JComponent
  {
    private Color color;
    private final ColorSelectPane this$0;

    public ColorCell()
    {
      this.this$0 = paramColorSelectPane;
      this.color = Color.white;
      enableEvents(16L);
      setBorder(new LineBorder(paramColorSelectPane.getColorCellBorderLineColor()));
      setCursor(new Cursor(12));
    }

    public ColorCell(, Color paramColor)
    {
      this(paramColorSelectPane);
      setColor(paramColor);
    }

    public void setColor()
    {
      this.color = paramColor;
      repaint();
    }

    public Color getColor()
    {
      return this.color;
    }

    public void paintComponent()
    {
      Dimension localDimension = getSize();
      Insets localInsets = getInsets();
      int i = localDimension.width - localInsets.left - localInsets.right;
      int j = localDimension.height - localInsets.top - localInsets.bottom;
      if (this.color == null)
      {
        paramGraphics.setColor(Color.white);
        paramGraphics.fillRect(localInsets.left, localInsets.top, localDimension.width - localInsets.left - localInsets.right, localDimension.height - localInsets.top - localInsets.bottom);
        paramGraphics.setColor(Color.gray);
        paramGraphics.drawLine(localInsets.left, localInsets.top, i, j);
        paramGraphics.drawLine(i, localInsets.top, localInsets.left, j);
      }
      else
      {
        paramGraphics.setColor(this.color);
        paramGraphics.fillRect(localInsets.left, localInsets.top, i, j);
      }
      if ((this.this$0.getColor() != null) && (this.this$0.getColor().equals(getColor())))
      {
        paramGraphics.setColor(Color.black);
        paramGraphics.drawRect(localInsets.left, localInsets.top, i - 1, j - 1);
      }
    }

    public void processMouseEvent()
    {
      if ((paramMouseEvent == null) || (paramMouseEvent.getID() == 502))
      {
        this.this$0.setColor(getColor());
        repaint();
      }
      if (paramMouseEvent != null)
        super.processMouseEvent(paramMouseEvent);
    }

    public Dimension getPreferredSize()
    {
      return this.this$0.getColorCellDimension();
    }

    public Dimension getMinimumSize()
    {
      return getPreferredSize();
    }
  }
}